package com.dwjm.exam.stu_list; // 请替换为实际的包名
import com.dwjm.exam.pojo.Dorm;
import com.dwjm.exam.utils.ConnectionDatabaseForMySQLUseJdbc; // 假设连接数据库工具类路径不变
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;



public class StudentListDaoImpl implements StudentListDao {
    Connection connection = null;
    PreparedStatement pstmt = null;
    ResultSet rset = null;

    public void DormDaoImpl() {
        connection = ConnectionDatabaseForMySQLUseJdbc.getConnection();
    }



    @Override
    public int addDorm(Dorm dorm) {
        try {
            // 插入语句对应dorm表字段
            pstmt = connection.prepareStatement("insert into dorm(dormNumber, dormType, totalBeds, occupiedBeds, availableBeds, building, floor, manager) values (?,?,?,?,?,?,?,?)");
            pstmt.setInt(1, dorm.getDormNumber());
            pstmt.setString(2, dorm.getDormType());
            pstmt.setInt(3, dorm.getTotalBeds());
            pstmt.setInt(4, dorm.getOccupiedBeds());
            pstmt.setInt(5, dorm.getAvailableBeds());
            pstmt.setString(6, dorm.getBuilding());
            pstmt.setString(7, dorm.getFloor());
            pstmt.setString(8, dorm.getManager());
            int i = pstmt.executeUpdate();
            return i == 1? 1 : 0;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }
}